package com.sts.transform.function;

import cn.hutool.core.util.RandomUtil;
import com.googlecode.aviator.runtime.function.AbstractFunction;
import com.googlecode.aviator.runtime.function.FunctionUtils;
import com.googlecode.aviator.runtime.type.AviatorBigInt;
import com.googlecode.aviator.runtime.type.AviatorObject;

import java.util.Map;

/**
 * @author lsl
 * @since 2025年07月08日 19:31
 */
public class RandIntFunction extends AbstractFunction {

    @Override
    public AviatorObject call(Map<String, Object> env, AviatorObject arg1, AviatorObject arg2) {
        Number left = FunctionUtils.getNumberValue(arg1, env);
        Number right = FunctionUtils.getNumberValue(arg2, env);
        return new AviatorBigInt(RandomUtil.randomLong(left.longValue(), right.longValue()));
    }

    @Override
    public String getName() {
        return "randInt";
    }
}
